package com.custom.headerpagerview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * @description：遮盖PagerView的贝塞尔曲线
 * @Author MRyan
 * @Date 2020/3/19 13:52
 * @Version 1.0
 */
public class ArcCoverView extends View {

    private Paint mPaint;
    private Path mPath;
    private int width;
    private int height;

    public ArcCoverView(Context context) {
        this(context, null);
    }

    public ArcCoverView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ArcCoverView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        width = context.getResources().getDisplayMetrics().widthPixels;
        height = 220;
        mPaint = new Paint();
        mPaint.setColor(Color.WHITE);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setAntiAlias(true);
        mPath = new Path();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mPath.moveTo(0, 0);
        mPath.quadTo(width / 2, height * 2 - 190, width, 0);
        mPath.lineTo(width, height);
        mPath.lineTo(0, height);
        canvas.drawPath(mPath, mPaint);
    }
}
